<template>
  <div class="register">
    <div class="register-box">
      <div class="title">
        <p>润云云盘</p>
      </div>
      <a-form :form="userForm" class="register-form">
        <a-form-item>
          <a-input v-model="userForm.username" placeholder="账号">
            <a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)" />
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-input
            v-model="userForm.password"
            type="password"
            placeholder="密码"
          >
            <a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)" />
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-input v-model="userForm.email" placeholder="邮箱">
            <a-icon slot="prefix" type="mail" style="color: rgba(0,0,0,.25)" />
          </a-input>
        </a-form-item>
        <a-form-item>
          <a-input v-model="userForm.phoneNumber" placeholder="手机号">
            <a-icon slot="prefix" type="phone" style="color: rgba(0,0,0,.25)" />
          </a-input>
        </a-form-item>
        <a-form-item style="text-align: center">
          <a-button
            type="primary"
            class="register-form-button"
            @click="registerButtonClick"
          >
            注册
          </a-button>
          <a-button class="register-form-button" @click="backButtonClick">
            返回
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      userForm: {
        username: '',
        password: '',
        email: '',
        phoneNumber: ''
      },
      authCode: ''
    }
  },
  methods: {
    registerButtonClick() {
      if (
        this.userForm.password.trim() === '' ||
        this.userForm.username.trim() === '' ||
        this.userForm.email.trim() === '' ||
        this.userForm.phoneNumber.trim() === ''
      ) {
        return this.$message.info('请填写注册信息')
      }
      this.$api.user.register(this.userForm).then((res) => {
        this.$message.success('注册成功')
        this.$router.push('/login')
      })
    },
    backButtonClick() {
      this.$router.push('/login')
    }
  },
  mounted() {
  }
}
</script>
<style lang="less" scoped>
.register {
  background: url('../assets/backgroud/login_bg.jpg') no-repeat;
  background-size: cover;
  position: fixed;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  .register-box {
    background-color: rgba(255, 255, 255, 0.95);
    position: relative;
    z-index: 3;
    max-width: 100%;
    width: 350px;
    margin: 120px auto 0px;
    padding: 30px 50px 30px 50px;
    border-radius: 5px;
    .title {
      font-size: 25px;
      color: #4c6c79;
      text-align: center;
    }
    .register-form {
      max-width: 300px;
      padding-top: 15px;
    }
    .register-form-button {
      width: 80%;
      margin-top: 20px;
    }
  }
}
</style>
